<%@ page contentType="text/html;charset=UTF-8" language="java"      %>
<%

    response.setHeader("Access-Control-Allow-Origin", "*");
    response.getWriter().write("hahahhaha");
%>
<html>
<script >
    window.header("Access-Control-Allow-Origin:*");
    function baidu(){
        var xmlhttp;
        if (window.XMLHttpRequest){
            //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlhttp = new XMLHttpRequest();
        }else {
            // IE6, IE5 浏览器执行代码
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.open("GET","https://www.baidu.com/",true);
        // xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        // xmlhttp.send("fname=Henry&lname=Ford");

        xmlhttp.onreadystatechange =function()
        {
            var str = "readyState = "+xmlhttp.readyState +"  xmlhttp.status = "+xmlhttp.status;
            alert(str)
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
               var str =  xmlhttp.responseText;
                document.getElementById("myDiv").innerHTML= str;
                alert(str)
            }else {

            }
        }
        xmlhttp.send();
        // xmlhttp.response.setRequestHeader("Access-Control-Allow-Origin", "*");


    }

</script>
<body>
<div id="myDiv"><h2>使用 AJAX 修改该文本内容</h2></div>
<button type="button" onclick="baidu()">修改内容</button>

<%--
    <div id="myDiv"></div>
--%>

</body>
</html>
